package com.ylx.code.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylx.code.bo.*;
import com.ylx.code.service.MarkInfoService;
import com.ylx.code.vo.MarkScanRecordVo;
import com.ylx.code.vo.MarkVo;
import com.ylx.code.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@AllArgsConstructor
@Api(tags = "商户管理")
@RequestMapping("/markCode")
public class MarkCodeController {

    private final MarkInfoService markInfoService;

    @GetMapping("/index")
    public Object addCustomView() {
        return "SUCCESS";
    }

    @ApiOperation(value = "商户详情")
    @GetMapping("/getMarkById")
    public Result<MarkVo> getMarkById(@RequestParam("id") Long id) {
        return Result.ok(markInfoService.markInfo(id));
    }

    @ApiOperation(value = "新建code")
    @PostMapping("/createCode")
    public Result<MarkVo> createCode() {
        return Result.ok(markInfoService.createCode());
    }

    @ApiOperation(value = "关联商户")
    @PostMapping("/connectMark")
    public Result<MarkVo> connectMark(@RequestBody @Validated ConnectMarkBo bo) {
        return Result.ok(markInfoService.connectMark(bo));
    }

    @ApiOperation(value = "商户详情")
    @PostMapping("/markInfo")
    public Result<MarkVo> markInfo(@RequestBody @Validated IdBo bo) {
        return Result.ok(markInfoService.markInfo(bo.getId()));
    }

    @ApiOperation(value = "商户列表")
    @PostMapping("/markList")
    public Result<Page<MarkVo>> markList(@RequestBody @Validated MarkListBo bo) {
        return Result.ok(markInfoService.markList(bo));
    }

    @ApiOperation(value = "删除商户")
    @PostMapping("/deleteMark")
    public Result<Object> deleteMark(@RequestBody @Validated IdBo bo) {
        markInfoService.deleteMark(bo.getId());
        return Result.ok();
    }

    @ApiOperation(value = "新增扫描记录")
    @PostMapping("/newScanRecord")
    public Result<MarkScanRecordVo> newScanRecord(@RequestBody @Validated NewScanRecordBo bo) {
        return Result.ok(markInfoService.newScanRecord(bo));
    }

    @ApiOperation(value = "扫描记录查询")
    @PostMapping("/scanRecordList")
    public Result<Page<MarkScanRecordVo>> scanRecordList(@RequestBody @Validated RecordListBo bo) {
        return Result.ok(markInfoService.scanRecordList(bo));
    }

    @ApiOperation(value = "删除记录")
    @PostMapping("/deleteRecord")
    public Result<Object> deleteRecord(@RequestBody @Validated IdBo bo) {
        markInfoService.deleteRecord(bo.getId());
        return Result.ok();
    }
}